<template>
  <el-select v-model="val" placeholder="请选择" clearable  @change="$emit('input', val)">
    <el-option
      v-for="item in list"
      :key="item.id"
      :label="item.label"
      :value="item.valueCode">
    </el-option>
  </el-select>
</template>
<script>
/**
 * This is a component file.
 * Generate By lanaya-generate Automatically.
 * Author: Dennis
 * Date: 2020-7-7 14:16:58
 */
export default {
  name: 'myDictSelect',
  props: {
    value: {
      type: String,
      default: ''
    },
    options: {
      type: Array,
      default: null
    },
    dictCode: {
      type: String,
      default: undefined
    }
  },
  data () {
    return {
      val: '',
      list: []
    };
  },
  watch: {
    value: function (val) {
      this.val = val;
    },
    options: function (newOptions, oldOptions) {
      if (newOptions) {
        this.list = JSON.parse(JSON.stringify(newOptions));
      }
    },
    dictCode: function (newCode, oldCode) {
      try {
        if (!this.options) {
          let temp = this.$store.getters['config/getDictByCodes'];
          temp('baowualertSeverity').then(res => {
            this.list = res;
          });
        }
      } catch (e) {
        console.log('Can not visite the Vuex now!');
      }
    }
  },
  mounted () {
    if (!this.options && this.dictCode) {
      let temp = this.$store.getters['config/getDictByCodes'];
      temp(this.dictCode).then(res => {
        this.list = res;
      });
    }
  }
};
</script>

<style lang="scss" module>
@import './../../../../src/style/default/DictSelect.scss';
</style>
